<?
class menu_block_controller extends block {

  protected $Items_Html = "";
  
  private function render_items($Pages) {
    $Module = request::$Module;
    $HTML = ""; 
    if (count($Pages)<=1)
      $Pages = array($Pages);    
    
    foreach ($Pages as $Page) {
      $Page_Name  = trim($Page["@attributes"]["name"]);
      $Page_Title = phrase::__(trim($Page["@attributes"]["title"]));
      $URL = $Module."/".$Page_Name;
      $Target = "_self";
      
      //check if has specific target for anchor tag
      if (isset($Page["@attributes"]["target"])) 
        $Target = $Page["@attributes"]["target"];
      
      //check if has specific url
      if (isset($Page["@attributes"]["url"])) 
        $URL = $Page["@attributes"]["url"];
      
      //check if is a muted menu item
      if (isset($Page["@attributes"]["muted"]))
        $Muted = strtolower(trim($Page["@attributes"]["muted"]));
      else
        $Muted = "false";            
      if ($Muted=="true") {
        $URL = "javascript:";
        $Target = "_self";
      }
      
      //before child items
      $HTML .= 
      "<li>\r\n".
      "  <a href='$URL' target='$Target'>$Page_Title</a>\r\n".
      "  <ul>\r\n";
      
      //child items
      if (isset($Page["page"]))
        $HTML .= $this->render_items($Page["page"]);
      
      //after child items
      $HTML .=
      "  </ul>\r\n".
      "</li>\r\n";
    }
    return $HTML;
  }
  
  public function prepare() {
    $Module_Info = system::get_module_info();
    $Menu = $Module_Info["menu"];
    $this->Items_Html = $this->render_items($Menu["page"]);
  }
  
  public function finish() {
  }
}